package com.jdbc.c3p0;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class myC3P0Utils {

	private static ComboPooledDataSource datasource = null;

	static {
		try {
			datasource = new ComboPooledDataSource("MySQL");
		} catch (Exception e) {
			throw new ExceptionInInitializerError(e);
		}

	}

	public static Connection getConnection() throws SQLException {
		return datasource.getConnection();
	}

	public static void release(Connection con, Statement st, ResultSet rs) {

		if (rs != null) {
			try {
				rs.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
			rs = null;
		}
		if (st != null) {
			try {
				st.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
			st = null;
		}
		if (con != null) {
			try {
				con.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
			con = null;
		}

	}

}
